package com.fz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fz.entity.Complain;
import com.fz.service.ComplainService;
import com.fz.vo.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 存储住户投诉信息 前端控制器
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@RestController
@RequestMapping("/complaint")
public class ComplainController {
    @Resource
    ComplainService complaintService;
    @GetMapping("/list")
    List<Complain> list(){
        return complaintService.list();
    }
    @GetMapping("/list1")
    public ResultVo<List<Complain>> list1(){
        return ResultVo.success(complaintService.list(),"投诉数据统计获取成功");
    }

    @PostMapping("/llist")
    ResultVo<IPage<Complain>> llist(Long userId, Integer pageNo, Integer pageSize)
    {return ResultVo.success(complaintService.getList(userId, pageNo, pageSize));}

    @PostMapping("/reject")
    ResultVo<Boolean> reject(Long id, Integer status,Integer statu){
        return ResultVo.success(complaintService.reject(id,status,statu),statu==2?"投诉已驳回成功":"投诉状态已重置，请尽快处理");
    }
    @PostMapping("/pass")
    ResultVo<Boolean> pass(Long id,Integer status,Integer statu){
        return ResultVo.success(complaintService.pass(id,status,statu),"投诉已通过成功");
    }

    @GetMapping("/getById")
    ResultVo<Complain> getById(Long id)
    {
        return ResultVo.success(complaintService.getById(id));
    }

    @GetMapping("/check")
    ResultVo<Boolean>check(Long id,String field,String value){
        return ResultVo.success(complaintService.check(id,field,value));
    }

    @PostMapping("/update")
    ResultVo<Boolean> update(Complain complaint){
        return ResultVo.success(complaintService.updateById(complaint),"修改投诉表单成功");
    }

    @PostMapping("/del")
    ResultVo<Boolean>del(Long id,Integer status)
    {
        return ResultVo.success(complaintService.del(id,status),"撤销投诉表单成功");
    }
    @PostMapping("/add")
    ResultVo<Boolean>add(Integer userId, String type, String content){
        return ResultVo.success(complaintService.add(Long.valueOf(userId), type, content),"添加投诉表单成功");
    }
    @PostMapping("/list2")
    ResultVo<IPage<Complain>> list2(Integer pageNo, Integer pageSize){
        return ResultVo.success(complaintService.showList( pageNo, pageSize));
    }
    @PostMapping("/search")
    ResultVo<IPage<Complain>> search(String input,Integer pageNo, Integer pageSize){
        return ResultVo.success(complaintService.search(input,pageNo,pageSize),"搜索成功！");
    }
}
